﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.Framework.ErrorLogging;
using PSE.Framework.Configuration;

namespace PSE.Framework.Process
{
    public abstract class BaseProgram
    {
        public static void Initialize(PSE.Framework.Configuration.SystemComponent system, PSE.Framework.Configuration.SystemComponent component)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            ApplicationConfiguration.Initialize(system, component);
        }

        public static void HandleException(Exception ex)
        {
            ErrorLogger.WriteLog(LogType.Error, ex);
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            HandleException((Exception)e.ExceptionObject);

            if (e.IsTerminating)
            {
                Environment.Exit(1);
            }
        }
    }
}
